<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>在职人员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form searchForm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="realName" id="realName" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">身份证号:</label>
            <div class="layui-input-inline">
                <input type="text" name="userCard" id="userCard" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
                <button class="layui-btn" lay-submit>清空</button>
            </div>
        </div>
    </div>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">发起聘请</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看详情</a>
    {{# if(d.employStatus==2){ }}
    <a class="layui-btn layui-btn-xs" lay-event="fire">解聘</a>
    {{# } }}
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    var configureCom = {};
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'matchDict'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var matchDict = layui.matchDict;
        configureCom = layui.configureCom;
        var cols = [[
            {field: 'realName', title: '姓名'},
            {field: 'userCard', title: '身份证号'},
            {
                field: 'seal', title: '从事职务', templet: function (d) {
                    return '<p>' + matchDict.name(d.seal, configure.DUTY_TYPE_CODE) + '</p>'
                }
            },
            {field: 'launchDate', title: '发起日期'},
            {field: 'procesDate', title: '人员处理日期'},
            {title: '操作', toolbar: '#barDemo', width: 150}
        ]];
        configureCom.tableRender(configure.COM_ZIZHI_USER_ONJOB_LIST_HTTP, {}, cols, 'dataList', 10, '', 'toolbarOrg');
        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            sessionFun.remove(configure.SESSION_ZIZHI_USER_LIST_DATA);
            switch (obj.event) {
                case 'add':
                    top.layer.open({
                        type: 2,
                        title: '发起聘请',
                        area: configureCom.Psize4,
                        content: configureCom.nocache(configure.COM_WAIT_ZIZHI_USER_LIST_HTML),
                        btn: ['选择'],
                        yes: function (index, layero) {
                            var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                            var data = iframeWin.getData();
                            sessionFun.set(configure.SESSION_CHOOSE_DATA, data);
                            top.layer.close(index);
                            zizhiUserInfoFun();
                        }
                    });
                    break;
            }
        });
        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_ZIZHI_LIST_DATA, data);
            if (obj.event === 'detail') {
                top.layer.open({
                    type: 2,
                    title: '查看',
                    area: configureCom.Psize1,
                    content: configureCom.nocache(configure.COM_EMPLOY_ZIZHI_USER_DETAIL_READ_HTML)
                });
            } else if (obj.event === 'fire') {
                top.layer.prompt({
                    formType: 2,
                    title: '请输入解雇原因！',
                    value: ''
                }, function (value, index) {
                    if (!value) {
                        top.layer.msg('请输入解雇原因！');
                        return false;
                    }
                    configureCom.postDataAjax(configure.COM_FIRE_ZIZHI_USER_HTTP, {
                        userId: data.userId,
                        reasonDismiss: value
                    }).then(function (res) {
                        top.layer.close(index);
                        top.layer.msg('保存成功！');
                        configureCom.tableReload(true);
                    });
                    layer.close(index);
                });
            }
        });

        //聘用人员详情
        function zizhiUserInfoFun() {
            top.layer.open({
                type: 2,
                title: '人员详情',
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.COM_EMPLOY_ZIZHI_USER_DETAIL_HTML),
                btn: ['发起聘请'],
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        configureCom.postDataAjax(configure.COM_EMPLOY_ZIZHI_USER_HTTP, res.result).then(function (res) {
                            top.layer.close(index);
                            top.layer.alert('注意:个人处理需登录个人账号后，在【聘用业务管理】-【企业聘用】中处理', {title: '聘用申请发送成功，请等待。'});
                            configureCom.tableReload(true);
                        });
                    });
                }
            });
        }

        //监听搜索
        configureCom.tableSearch();
    });
</script>
</body>
</html>